<?php
namespace app\admin\controller;

use app\admin\logic\AuthLogic;
use app\common\respond\HttpApi;

/**
 * 登录类
 */
class LoginController
{
    /**
     * @Description 登录
     * @author: zj
     * @time 2024/03/07 17:48:11
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function login()
    {
        $param = [
            'name' => request()->post('name'),
            'password' => request()->post('password'),
        ];

        $rule = [
            'name' => 'require|max:20',
            'password' => 'require|max:30',
        ];
        //验证参数
        validate($rule)->check($param);
        //登录业务逻辑
        $loginLogic = new AuthLogic();
        $data = $loginLogic->login($param['name'], $param['password']);

        $respond = new HttpApi();

        return $respond->success($data);
    }

    /**
     * @Description 退出登录
     * @author: zj
     * @time 2024/03/05 11:57:59
     * @return \think\response\Json
     */
    public function logout()
    {
        $token = request()->header('token');
        $loginLogic = new AuthLogic();
        $loginLogic->logout($token);

        $respond = new HttpApi();

        return $respond->success([]);
    }
    
}
